package cn.lin.mapper;

import cn.lin.domain.Classes;
import cn.lin.domain.Organization;
import cn.lin.domain.Role;
import cn.lin.vo.ClassesVo;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface ClassesRapper {

    @Select("SELECT c.role_name\n" +
            "FROM \n" +
            "user a\n" +
            "LEFT JOIN\n" +
            "user_role b\n" +
            "ON\n" +
            "a.id=b.user_id\n" +
            "LEFT JOIN\n" +
            "role c\n" +
            "ON\n" +
            "b.role_id=c.id\n" +
            "WHERE a.id=#{id}")
    Role findUser(int id);

//    @Select("SELECT  c.*\n" +
//            "FROM user a\n" +
//            "LEFT JOIN class_stu b\n" +
//            "ON\n" +
//            " a.id = b.user_id\n" +
//            "LEFT JOIN classes c\n" +
//            "ON\n" +
//            "b.class_id = c.id  \n" +
//            "WHERE a.username = #{username} AND is_end=#{is_end};")
//    List<Classes> findstudentclasses(String username,String is_end);



   @Select("SELECT  a.username,b.*\n" +
           "FROM user a\n" +
           "LEFT JOIN\n" +
           "classes b\n" +
           "ON\n" +
           "a.id = b.teacher_id  \n" +
           "WHERE a.id = #{id}\n" +
           "AND\n" +
           "b.is_end=#{is_end};")
    List<ClassesVo> findteacherclasses(int id,String is_end);



   //手机段班级产看所有，结束和未结束
   @Select("SELECT d.username, c.*\n" +
           "FROM user a\n" +
           "LEFT JOIN class_stu b\n" +
           " ON a.id = b.user_id\n" +
           "LEFT JOIN classes c\n" +
           " ON b.class_id = c.id\n" +
           "LEFT JOIN user d\n" +
           " ON c.teacher_id = d.id\n" +
           "WHERE a.id = #{id}\n" +
           "AND c.is_end=#{is_end};")
   List<ClassesVo> findeteacherclassesall(int id, String is_end);


   //机构渲染
    @Select("SELECT * FROM organization WHERE  level=1")
    List<Organization> findAllOrganization();

}
